home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / piblist.arc / POSITION.PAS < prev    next >
Pascal/Delphi Source File  |  1985-03-28  |  7KB  |  188 lines

  1. (*----------------------------------------------------------------------*)
  2. (*             Position -- parse positioning commands                   *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Position( VAR legal: BOOLEAN );
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*   Procedure:   Position                                              *)
  10. (*                                                                      *)
  11. (*   Purpose:     Parses positioning commands.                          *)
  12. (*                                                                      *)
  13. (*   Calling sequence:                                                  *)
  14. (*                                                                      *)
  15. (*      Position( VAR legal : BOOLEAN );                                *)
  16. (*                                                                      *)
  17. (*         legal --- returned TRUE if command was OK.                   *)
  18. (*                                                                      *)
  19. (*   Calls:  MIN                                                        *)
  20. (*           RMAX                                                        *)
  21. (*           RMAX                                                       *)
  22. (*           Find_Line                                                  *)
  23. (*           Find_Page                                                  *)
  24. (*           Find_String                                                *)
  25. (*           Skipbl                                                     *)
  26. (*           Number                                                     *)
  27. (*                                                                      *)
  28. (*----------------------------------------------------------------------*)
  29.  
  30. VAR
  31.    c:   CHAR;
  32.    n:   REAL;
  33.    sn:  INTEGER;
  34.    rel: BOOLEAN;
  35.    ow:  INTEGER;
  36.    I:   INTEGER;
  37.  
  38. BEGIN (* Position *)
  39.  
  40.                                    (* Assume command is OK *)
  41.    legal := TRUE;
  42.                                    (* Look for initial number signalling *)
  43.                                    (* relative positioning               *)
  44.  
  45.    IF Command[Cind] IN ['+','-','0'..'9'] THEN
  46.       BEGIN
  47.          rel  := TRUE;
  48.                                    (* Remember sign *)
  49.          sn   := +1;
  50.          IF Command[Cind] IN ['+','-'] THEN
  51.             BEGIN
  52.                IF Command[Cind] = '-' THEN sn := -1;
  53.                Cind := Cind + 1;
  54.             END;
  55.                                    (* Pick up the number *)
  56.          Number( n );
  57.  
  58.          n := sn * n;
  59.                                    (* Skip any blanks after number *)
  60.          Skipbl;
  61.                                    (* If no command follows, assume *)
  62.                                    (* 'S' = screen request          *)
  63.  
  64.          IF Command[Cind] = nul THEN
  65.             c := 'S'
  66.          ELSE                      (* Pick up command letter *)
  67.             BEGIN
  68.  
  69.                c    := Command[Cind];
  70.                Cind := Cind + 1;
  71.  
  72.                IF c = '''' THEN          (* Get search string *)
  73.                   BEGIN
  74.                      IF Command[Cind] <> Nul THEN
  75.                         BEGIN
  76.  
  77.                            Search_Str  := '';
  78.                            Search_Lpos := 0;
  79.                            Search_Line := 0;
  80.  
  81.                            WHILE( Command[Cind] <> Nul ) DO
  82.                               BEGIN
  83.                                  Search_Str := Search_Str + Command[Cind];
  84.                                  Cind       := Cind + 1;
  85.                               END;
  86.  
  87.                         END;
  88.                   END;
  89.  
  90.             END
  91.       END
  92.    ELSE                            (* No initial number -- get command *)
  93.       BEGIN
  94.  
  95.          c    := Command[Cind];
  96.          Cind := Cind + 1;
  97.  
  98.          SkipBl;
  99.  
  100.          rel  := ( Command[Cind] = NUL );
  101.  
  102.                                    (* Trailing number = absolute positioning *)
  103.  
  104.          IF c = '''' THEN          (* Get search string *)
  105.             BEGIN
  106.                IF Command[Cind] <> Nul THEN
  107.                   BEGIN
  108.  
  109.                      Search_Str  := '';
  110.                      Search_Line := 0;
  111.                      Search_Lpos := 0;
  112.  
  113.                      WHILE( Command[Cind] <> Nul ) DO
  114.                         BEGIN
  115.                            Search_Str := Search_Str + Command[Cind];
  116.                            Cind       := Cind + 1;
  117.                         END;
  118.  
  119.                   END;
  120.             END
  121.          ELSE
  122.             Number( n );
  123.  
  124.       END;
  125.                                    (* Skip any trailing blanks *)
  126.    SkipBl;
  127.                                    (* If reached end of command string, *)
  128.                                    (* command is OK.                    *)
  129.    legal := Command[Cind] = nul;
  130.  
  131.                                    (* execute positioning command if   *)
  132.                                    (* it is legal.                     *)
  133.    IF legal THEN
  134.  
  135.       CASE c OF
  136.  
  137.          'L', 'l':
  138.             IF rel THEN
  139.                Find_Line( RMAX( top_line + n , 1.0 ) )
  140.             ELSE
  141.                Find_Line( RMAX( n , 1.0 ) );
  142.  
  143.          'P', 'p':
  144.             IF rel THEN
  145.                Find_Page( RMAX( top^.pnum + n , 1.0 ) )
  146.             ELSE
  147.                Find_Page( RMAX( n , 1.0 ) );
  148.  
  149.          'S', 's':
  150.             IF rel THEN
  151.                Find_Line( RMAX( top_line + Height * n , 1.0 ) )
  152.             ELSE
  153.                Find_Line( RMAX( Height * n - Height + 1.0 , 1.0 ) );
  154.  
  155.          'C', 'c':
  156.             BEGIN
  157.                IF rel THEN
  158.                   first_col := MAX( TRUNC( first_col + n ) , 1 )
  159.                ELSE
  160.                   first_col := MAX( TRUNC( n ) , 1 );
  161.                IF lpt THEN first_col := MAX( first_col , 2 )
  162.             END;
  163.  
  164.          'W', 'w':
  165.             BEGIN
  166.                ow := width;
  167.                IF rel THEN
  168.                   width := MAX( width + TRUNC( n ) , 1 )
  169.                ELSE
  170.                   width := MAX( TRUNC( n ) , 1 );
  171.             END;
  172.  
  173.          '''':
  174.             BEGIN
  175.                GoToXY( WhereX + 1 , WhereY );
  176.  
  177.                WRITE( '... Searching');
  178.  
  179.                Find_Line( RMAX( Search_Line + 1 , Top^.Lnum ) );
  180.                Find_String( Search_Str );
  181.             END;
  182.  
  183.       ELSE
  184.          legal := FALSE;
  185.       END;
  186.  
  187. END   (* Position *);
  188.